package com.zjs.asynctest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Future;

/**
 * Created with IntelliJ IDEA.
 *
 * @author : zjs
 * @date : 2022/1/28 10:16
 * Description:
 */
@RestController
@RequestMapping("/async")
public class AsyncController {

    @Autowired
    private AsyncService asyncService;

    @GetMapping("test")
    public Integer methodA() throws Exception{
        long start = System.currentTimeMillis();
        Future<Integer> future1 = asyncService.methodB();
        Future<Integer> future2 = asyncService.methodC();
        Future<Integer> future3 = asyncService.methodD();
        Integer x = future1.get();
        Integer y = future2.get();
        Integer z = future3.get();
        long end = System.currentTimeMillis();
        System.out.println("耗时：" + (end - start));
        return x + y +z;
    }
}
